#include "person.h"
#include <iostream>

using namespace std;

// 构造函数，无参数
Person::Person() : id(0), name("unknown") {}

// 构造函数，有参数
Person::Person(const int id, const std::string &name) {
	this->id = id;
	this->name = name;
}

// 拷贝构造函数
Person::Person(const Person &other) {
	this->id = other.id;
	this->name = other.name;
}

// 析构函数
Person::~Person() {
	this->id = 0;
	this->name = "";
	cout << "Person析构函数" << endl;
}

// 设置id
void Person::SetId(const int id) { this->id = id; }

// 设置姓名
void Person::SetName(const std::string &name) { this->name = name; }

// 获取id
int Person::GetId() const { return this->id; }

// 获取姓名
std::string Person::GetName() { return this->name; }

// 打印信息
void Person::Print() const { cout << "Person {id:" << this->id << ",name:" << this->name << "}" << endl; }

// 重载赋值运算符
Person &Person::operator=(const Person &other) {
	if (this == &other) {
		return *this;
	}
	this->id = other.id;
	this->name = other.name;
	return *this;
}

// 重载等于运算符
bool Person::operator==(const Person &other) const {
	if (this->id == other.id && this->name == other.name)
		return true;
	return false;
}

// 重载输出运算符
std::ostream &operator<<(std::ostream &out, const Person &person) {
	out << "Person {id:" << person.id << ",name:" << person.name << "}";
	return out;
}